package net.flintx.array;

import java.util.Arrays;

/**
 * Created by flintx on 2018/1/10.
 */
public class MoveZeroes {
    public void moveZeroes(int[] nums) {
        int index = 0, noZeroIndex = 1;
        while (index < nums.length) {
            if (nums[index] == 0) {
                while (noZeroIndex < nums.length && nums[noZeroIndex] == 0)
                    noZeroIndex += 1;
                if (noZeroIndex == nums.length)
                    break;
                nums[index] = nums[noZeroIndex];
                nums[noZeroIndex] = 0;
            }
            index += 1;
            noZeroIndex = index + 1;
        }
    }

    public static void main(String[] args) {
        int[] nums = {0, 1, 0, 3, 12};
        new MoveZeroes().moveZeroes(nums);
        System.out.println(Arrays.toString(nums));
    }
}
